package com.franklin.icharm;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class UserConfig {
		
// use String.replace to put the variable on {0}, {1}....
		public final static String KV_USER_EMAIL = "User_Email";
		public final static String KV_UNGROUP_NOTIFY = "Ungroup_Notify";
		public final static String KV_VIP_NOTIFY = "Vip_Notify";
		public final static String KV_VIP_NAME = "Vip_Name";
		public final static String KV_VIP_PHONE = "Vip_Phone";
		public final static String KV_CALL0_NOTIFY= "Caller_{0}_Notify";
		public final static String KV_CALL0_NAMES1 = "Caller_{0}_Name_{1}";
		public final static String KV_CALL0_PHONE1 = "Caller_{0}_Phone_{1}";
		public final static String KV_CALL0_TOTAL_NAME = "Caller_{0}_NumOfName";
		public final static String KV_APP0_NOTIFY = "App_{0}_Notify";
		public final static String KV_APP0_NAME=	"App_{0}_Name";
		public final static String KV_TOUCH0_TYPE = "Touch_x{0}_Type";
		public final static String KV_TOUCH0_SMS_NAME ="Touch_x{0}_SMS_NAME";
		public final static String KV_TOUCH0_SMS_MSG = "Touch_x{0}_SMS_MSG";
		public final static String KV_SETTING_OUTOFRANGE = "Setting_OutOfRange";
		public final static String KV_SETTING_REJECTCALLREPLY = "Setting_RejectCallReply";
		public final static String KV_SETTING_RECORD_FILE = "Setting_Record_File";
		public final static String KV_DEVICE_BINDING_ADDRESS = "BLE_Device_Address"; 
		public final static String KV_DEVICE_CONNECTED = "BLE_Device_Connected"; 

		public final static String APP_NAME_CALENDAR = "Calendar";
		public final static String APP_NAME_SMS = "SMS";
		public final static String APP_NAME_MAIL = "Mail";
		
		public final static String ACTION_NAME_SEND_SMS = "Send SMS";
		public final static String ACTION_NAME_TAKE_PHOTO = "Take photo";
		public final static String ACTION_NAME_PLAY_MUSIC = "Play music using default player";
		public final static String ACTION_NAME_NEXT_SONG = "Next song using default player";
		public final static String ACTION_NAME_PREV_SONG = "Previous song using default player";
		public final static String ACTION_NAME_GOOGLE_PLAY_MUSIC = "Play music using Google player";
		public final static String ACTION_NAME_GOOGLE_NEXT_SONG = "Next song using Google player";
		public final static String ACTION_NAME_GOOGLE_PREV_SONG = "Previous song using Google player";
		public final static String ACTION_NAME_SPOTIFY_PLAY_MUSIC = "Play music using Spotify";
		public final static String ACTION_NAME_SPOTIFY_NEXT_SONG = "Next song using Spotify";
		public final static String ACTION_NAME_SPOTIFY_PREV_SONG = "Previous song using Spotify";
		
		public final static String VERSION = "userconfig_version";
		private String myVersion = "1.0";
		
		
		private SharedPreferences preferences ;
		Context mContext ;
		
		public UserConfig(Context mContext) {
			this.mContext = mContext;
			preferences = PreferenceManager.getDefaultSharedPreferences(this.mContext);
			String ver = getConfString(VERSION,null);
			if (ver == null)
			{
				loadDefaultValues();
			}
		}
		
		public boolean loadDefaultValues()
		{
			Editor ed = preferences.edit();
			ed.putString(VERSION, myVersion);
			ed.putBoolean(KV_UNGROUP_NOTIFY, true);
			ed.putInt(KV_CALL0_TOTAL_NAME.replace("{0}", "1"), 0);
			ed.putInt(KV_CALL0_TOTAL_NAME.replace("{0}", "2"), 0);
			ed.putInt(KV_CALL0_TOTAL_NAME.replace("{0}", "3"), 0);
			ed.putInt(KV_CALL0_TOTAL_NAME.replace("{0}", "4"), 0);
			ed.putBoolean(KV_APP0_NOTIFY.replace("{0}", "1"), true);
			ed.putString(KV_APP0_NAME.replace("{0}", "1"), APP_NAME_CALENDAR);
			ed.putBoolean(KV_APP0_NOTIFY.replace("{0}", "2"), true);
			ed.putString(KV_APP0_NAME.replace("{0}", "2"), APP_NAME_SMS);
			ed.putBoolean(KV_APP0_NOTIFY.replace("{0}", "3"), true);
			ed.putString(KV_APP0_NAME.replace("{0}", "3"), APP_NAME_MAIL);
			ed.putBoolean(KV_APP0_NOTIFY.replace("{0}", "4"), false);

			ed.putString(KV_TOUCH0_TYPE.replace("{0}", "1"), ACTION_NAME_TAKE_PHOTO);
			ed.putString(KV_TOUCH0_TYPE.replace("{0}", "2"), ACTION_NAME_PLAY_MUSIC);
			ed.putString(KV_TOUCH0_TYPE.replace("{0}", "3"), ACTION_NAME_NEXT_SONG);
			ed.putString(KV_TOUCH0_TYPE.replace("{0}", "4"), ACTION_NAME_PREV_SONG);
			ed.putBoolean(KV_SETTING_OUTOFRANGE, true);
			return ed.commit();
		}
		
		public void setConf(String sKey, boolean bValue)
		{
			preferences.edit().putBoolean(sKey, bValue).commit();
		}


		public void setConf(String sKey, int iValue)
		{
			preferences.edit().putInt(sKey, iValue).commit();

		}

		public void setConf(String sKey, String sValue)
		{
			preferences.edit().putString(sKey, sValue).commit();
		}

		public String getConfString(String sKey, String sDef)
		{
			return preferences.getString(sKey, sDef);
		}

		public int getConfInt(String sKey, int iDef)
		{
			return preferences.getInt(sKey, iDef);
		}

		public boolean getConfBoolean(String sKey, boolean bDef)
		{
			return preferences.getBoolean(sKey, bDef);
		}

}
